/*
 * Or.cpp
 *
 * Created on: 05-05-2014
 *     Author: A.W. Janisse
 *
 * Version 1.0: 24-05-2014, Final release
 */

#include <sstream>
#include "Or.h"

Or::Or(int x, int y, string type)
:TwoEntry(x, y, type)
{
}

int Or::getOutputValue()
{
    int v1 = 0;
    int v2 = 0;

    if(getEntry(0) != NULL)
        v1 = getEntry(0)->getOutputValue();

    if(getEntry(1) != NULL)
        v2 = getEntry(1)->getOutputValue();

    return v1 || v2;
}

string Or::getDrawingInstruction()
{
   stringstream result;

    int v1 = 0;
    int v2 = 0;
    if(getEntry(0) != NULL){
        v1 = getEntry(0)->getOutputValue();

        result << "connection"; // gate of connection
        result << ",";
        result << (v1 ? "H" : "L");
        result << ",";
        result << getEntry(0)->getX() + 8;
        result << ",";
        result << getEntry(0)->getY() + 3;
        result << ",";
        result << getX();
        result << ",";
        result << getY() + 2;
        result << "\n";
    }

    if(getEntry(1) != NULL){
        v2 = getEntry(1)->getOutputValue();

        result << "connection"; // gate of connection
        result << ",";
        result << (v2 ? "H" : "L");
        result << ",";
        result << getEntry(1)->getX() + 8;
        result << ",";
        result << getEntry(1)->getY() + 3;
        result << ",";
        result << getX();
        result << ",";
        result << getY() + 4;
        result << "\n";
    }

    result << "gate";           // gate of connection
    result << ",";
    result << getNumber();      // nummer
    result << ",";
    result << getType();        // type
    result << ",";
    result << getX();           // x positie
    result << ",";
    result << getY();           // y positie
    result << ",";
    result << 2;                // Two inputs
    result << ",";
    result << (v1 ? "H" : "L"); // value input 1
    result << ",";
    result << (v2 ? "H" : "L"); // value input 2
    result << ",";
    result << (getOutputValue() ? "H" : "L"); // value output
    result << "\n";

    return result.str();
}
